var followId = JSON.parse(sessionStorage.getItem("followId"));
var type = JSON.parse(sessionStorage.getItem("type"));
var index = 0;

// 视频URL
var videoUrl = "";

$(function () {
    if (type == "jcyk") {
        getResource();
    } else if (type == "fourBook_shiPinSuCai") {
        getFourBookShiPinSuCai();
    } else if (type == "fourBook_jingCaiYiKe") {
        getFourBookJingCaiYiKe();
    } else if (type == "mingShi_woDeShiPin") {
        getMingShiWoDeShiPin();
    } else if (type == "ggzyk_zheJiangShiPin") {
        getGgzykZheJiangShiPin();
    } else if (type == "zjjs_zheJiangShiPin") {
        getGgzykZheJiangShiPin();
    } else if (type == "shouYe_jingCaiYiKe") {
        getResource();
    }

    $("#downloadBtn").click(function () {
        var downloadForm = $("<form method='get'></form>");

        downloadForm.attr("action", videoUrl);

        $(document.body).append(downloadForm);

        //提交表单，实现下载
        downloadForm.submit();
    });
})

// 精彩一课
function getResource() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getResource_fun);
}
function getResource_fun(res) {
    type = "jcyk";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        var videoObject = {
            //playerID:'ckplayer01',//播放器ID，第一个字符不能是数字，用来在使用多个播放器时监听到的函数将在所有参数最后添加一个参数用来获取播放器的内容
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            //autoplay: true, //是否自动播放
            //duration: 500, //设置视频总时间
            cktrack: '', //字幕文件 material/srt.srt
            poster: videoLists.pic, //封面图片 material/poster.jpg
            preview: { //预览图片
                file: ['', ''], // ../material/mydream_en1800_1010_01.png ../material/mydream_en1800_1010_02.png
                scale: 2
            },
            config: '', //指定配置函数
            debug: true, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            drag: 'start', //拖动的属性
            seek: 0, //默认跳转的时间
            //playbackrate:1,//默认速度的编号，只对html5有效,设置成-1则不显示倍速
            //advertisements:'website:ad.json',
            //front:'frontFun',//上一集的操作函数
            //next:'nextFun',//下一集的操作函数
            //广告部分开始
            adfront: '', // 前置广告 http://www.ckplayer.com/yytf/swf/front001.swf,http://www.ckplayer.com/yytf/swf/front002.swf
            adfronttime: '15,15',
            adfrontlink: '',
            adpause: '', // http://www.ckplayer.com/yytf/swf/pause001.swf,http://www.ckplayer.com/yytf/swf/pause002.swf
            adpausetime: '5,5',
            adpauselink: '',
            adinsert: '', // http://www.ckplayer.com/yytf/swf/insert001.swf,http://www.ckplayer.com/yytf/swf/insert002.swf
            adinserttime: '10,10',
            adinsertlink: '',
            inserttime: '10,80',
            adend: '', // http://www.ckplayer.com/yytf/swf/end001.swf,http://www.ckplayer.com/yytf/swf/end002.swf
            adendtime: '15,15',
            adendlink: '',
            //广告部分结束
            promptSpot: [ //提示点
                {
                    words: '提示点文字01',
                    time: 30
                },
                {
                    words: '提示点文字02',
                    time: 150
                }
            ],
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //live:true,//是否是直播视频，true=直播，false=点播
            video: [
                [basePath + videoLists.fileUrl, 'video/mp4', '中文高清', 0]
                // [basePath + videoLists.file, 'video/mp4', '英文超清', 0],
                // [basePath + videoLists.file, 'video/mp4', '英文高清', 10],
                // [basePath + videoLists.file, 'video/mp4', '中文标清', 0]
            ]
        };
        var player = new ckplayer(videoObject);
    }
}

// 视频素材
function getFourBookShiPinSuCai() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getFourBookShiPinSuCaiRes);
}
function getFourBookShiPinSuCaiRes(res) {
    type = "fourBook_shiPinSuCai";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        var videoObject = {
            //playerID:'ckplayer01',//播放器ID，第一个字符不能是数字，用来在使用多个播放器时监听到的函数将在所有参数最后添加一个参数用来获取播放器的内容
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            //autoplay: true, //是否自动播放
            //duration: 500, //设置视频总时间
            cktrack: '', //字幕文件 material/srt.srt
            poster: videoLists.pic, //封面图片 material/poster.jpg
            preview: { //预览图片
                file: ['', ''], // ../material/mydream_en1800_1010_01.png ../material/mydream_en1800_1010_02.png
                scale: 2
            },
            config: '', //指定配置函数
            debug: true, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            drag: 'start', //拖动的属性
            seek: 0, //默认跳转的时间
            //playbackrate:1,//默认速度的编号，只对html5有效,设置成-1则不显示倍速
            //advertisements:'website:ad.json',
            //front:'frontFun',//上一集的操作函数
            //next:'nextFun',//下一集的操作函数
            //广告部分开始
            adfront: '', // 前置广告 http://www.ckplayer.com/yytf/swf/front001.swf,http://www.ckplayer.com/yytf/swf/front002.swf
            adfronttime: '15,15',
            adfrontlink: '',
            adpause: '', // http://www.ckplayer.com/yytf/swf/pause001.swf,http://www.ckplayer.com/yytf/swf/pause002.swf
            adpausetime: '5,5',
            adpauselink: '',
            adinsert: '', // http://www.ckplayer.com/yytf/swf/insert001.swf,http://www.ckplayer.com/yytf/swf/insert002.swf
            adinserttime: '10,10',
            adinsertlink: '',
            inserttime: '10,80',
            adend: '', // http://www.ckplayer.com/yytf/swf/end001.swf,http://www.ckplayer.com/yytf/swf/end002.swf
            adendtime: '15,15',
            adendlink: '',
            //广告部分结束
            promptSpot: [ //提示点
                {
                    words: '提示点文字01',
                    time: 30
                },
                {
                    words: '提示点文字02',
                    time: 150
                }
            ],
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //live:true,//是否是直播视频，true=直播，false=点播
            video: [
                [basePath + videoLists.fileUrl, 'video/mp4', '中文高清', 0]
                // [basePath + videoLists.file, 'video/mp4', '英文超清', 0],
                // [basePath + videoLists.file, 'video/mp4', '英文高清', 10],
                // [basePath + videoLists.file, 'video/mp4', '中文标清', 0]
            ]
        };
        var player = new ckplayer(videoObject);
    }
}

// 四本书-->精彩一课
function getFourBookJingCaiYiKe() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getFourBookJingCaiYiKeRes);
}
function getFourBookJingCaiYiKeRes(res) {
    type = "fourBook_shiPinSuCai";
    var videoLists = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        var videoObject = {
            //playerID:'ckplayer01',//播放器ID，第一个字符不能是数字，用来在使用多个播放器时监听到的函数将在所有参数最后添加一个参数用来获取播放器的内容
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            //autoplay: true, //是否自动播放
            //duration: 500, //设置视频总时间
            cktrack: '', //字幕文件 material/srt.srt
            poster: videoLists.pic, //封面图片 material/poster.jpg
            preview: { //预览图片
                file: ['', ''], // ../material/mydream_en1800_1010_01.png ../material/mydream_en1800_1010_02.png
                scale: 2
            },
            config: '', //指定配置函数
            debug: true, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            drag: 'start', //拖动的属性
            seek: 0, //默认跳转的时间
            //playbackrate:1,//默认速度的编号，只对html5有效,设置成-1则不显示倍速
            //advertisements:'website:ad.json',
            //front:'frontFun',//上一集的操作函数
            //next:'nextFun',//下一集的操作函数
            //广告部分开始
            adfront: '', // 前置广告 http://www.ckplayer.com/yytf/swf/front001.swf,http://www.ckplayer.com/yytf/swf/front002.swf
            adfronttime: '15,15',
            adfrontlink: '',
            adpause: '', // http://www.ckplayer.com/yytf/swf/pause001.swf,http://www.ckplayer.com/yytf/swf/pause002.swf
            adpausetime: '5,5',
            adpauselink: '',
            adinsert: '', // http://www.ckplayer.com/yytf/swf/insert001.swf,http://www.ckplayer.com/yytf/swf/insert002.swf
            adinserttime: '10,10',
            adinsertlink: '',
            inserttime: '10,80',
            adend: '', // http://www.ckplayer.com/yytf/swf/end001.swf,http://www.ckplayer.com/yytf/swf/end002.swf
            adendtime: '15,15',
            adendlink: '',
            //广告部分结束
            promptSpot: [ //提示点
                {
                    words: '提示点文字01',
                    time: 30
                },
                {
                    words: '提示点文字02',
                    time: 150
                }
            ],
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //live:true,//是否是直播视频，true=直播，false=点播
            video: [
                [basePath + videoLists.fileUrl, 'video/mp4', '中文高清', 0]
                // [basePath + videoLists.file, 'video/mp4', '英文超清', 0],
                // [basePath + videoLists.file, 'video/mp4', '英文高清', 10],
                // [basePath + videoLists.file, 'video/mp4', '中文标清', 0]
            ]
        };
        var player = new ckplayer(videoObject);
    }
}

// 我的视频
function getMingShiWoDeShiPin() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getResourceById", getMingShiWoDeShiPinRes);
}
function getMingShiWoDeShiPinRes(res) {
    type = "";
    var videoLists = res.obj;
    // console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.url;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        var videoObject = {
            //playerID:'ckplayer01',//播放器ID，第一个字符不能是数字，用来在使用多个播放器时监听到的函数将在所有参数最后添加一个参数用来获取播放器的内容
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            //autoplay: true, //是否自动播放
            //duration: 500, //设置视频总时间
            cktrack: '', //字幕文件 material/srt.srt
            poster: videoLists.pic, //封面图片 material/poster.jpg
            preview: { //预览图片
                file: ['', ''], // ../material/mydream_en1800_1010_01.png ../material/mydream_en1800_1010_02.png
                scale: 2
            },
            config: '', //指定配置函数
            debug: true, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            drag: 'start', //拖动的属性
            seek: 0, //默认跳转的时间
            //playbackrate:1,//默认速度的编号，只对html5有效,设置成-1则不显示倍速
            //advertisements:'website:ad.json',
            //front:'frontFun',//上一集的操作函数
            //next:'nextFun',//下一集的操作函数
            //广告部分开始
            adfront: '', // 前置广告 http://www.ckplayer.com/yytf/swf/front001.swf,http://www.ckplayer.com/yytf/swf/front002.swf
            adfronttime: '15,15',
            adfrontlink: '',
            adpause: '', // http://www.ckplayer.com/yytf/swf/pause001.swf,http://www.ckplayer.com/yytf/swf/pause002.swf
            adpausetime: '5,5',
            adpauselink: '',
            adinsert: '', // http://www.ckplayer.com/yytf/swf/insert001.swf,http://www.ckplayer.com/yytf/swf/insert002.swf
            adinserttime: '10,10',
            adinsertlink: '',
            inserttime: '10,80',
            adend: '', // http://www.ckplayer.com/yytf/swf/end001.swf,http://www.ckplayer.com/yytf/swf/end002.swf
            adendtime: '15,15',
            adendlink: '',
            //广告部分结束
            promptSpot: [ //提示点
                {
                    words: '提示点文字01',
                    time: 30
                },
                {
                    words: '提示点文字02',
                    time: 150
                }
            ],
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //live:true,//是否是直播视频，true=直播，false=点播
            video: [
                [basePath + videoLists.url, 'video/mp4', '中文高清', 0]
                // [basePath + videoLists.file, 'video/mp4', '英文超清', 0],
                // [basePath + videoLists.file, 'video/mp4', '英文高清', 10],
                // [basePath + videoLists.file, 'video/mp4', '中文标清', 0]
            ]
        };
        var player = new ckplayer(videoObject);
    }
}

// 浙江视频
function getGgzykZheJiangShiPin() {
    var data = {
        id: parseInt(followId)
    };

    AjaxSubmit("GET", data, baseUrl + "/common/resource/searchCommonResource", getGgzykZheJiangShiPinRes);
}
function getGgzykZheJiangShiPinRes(res) {
    type = "ggzyk_zheJiangShiPin";
    var videoLists = res.obj.content[0];
    console.log(res);
    if (res.status == "SUCCESS") {
        videoUrl = videoLists.fileUrl;
        $(".videobox").find("h3").html(videoLists.title);
        $(".videobox").find("p").append('<span>来源：</span><span>' + videoLists.whereFrom + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>时间：</span><span>' + changeTime(videoLists.creatTime) + '</span>');
        var videoObject = {
            //playerID:'ckplayer01',//播放器ID，第一个字符不能是数字，用来在使用多个播放器时监听到的函数将在所有参数最后添加一个参数用来获取播放器的内容
            container: '#video', //容器的ID或className
            variable: 'player', //播放函数名称
            loaded: 'loadedHandler', //当播放器加载后执行的函数
            loop: true, //播放结束是否循环播放
            //autoplay: true, //是否自动播放
            //duration: 500, //设置视频总时间
            cktrack: '', //字幕文件 material/srt.srt
            poster: videoLists.pic, //封面图片 material/poster.jpg
            preview: { //预览图片
                file: ['', ''], // ../material/mydream_en1800_1010_01.png ../material/mydream_en1800_1010_02.png
                scale: 2
            },
            config: '', //指定配置函数
            debug: true, //是否开启调试模式
            //flashplayer: true, //强制使用flashplayer
            drag: 'start', //拖动的属性
            seek: 0, //默认跳转的时间
            //playbackrate:1,//默认速度的编号，只对html5有效,设置成-1则不显示倍速
            //advertisements:'website:ad.json',
            //front:'frontFun',//上一集的操作函数
            //next:'nextFun',//下一集的操作函数
            //广告部分开始
            adfront: '', // 前置广告 http://www.ckplayer.com/yytf/swf/front001.swf,http://www.ckplayer.com/yytf/swf/front002.swf
            adfronttime: '15,15',
            adfrontlink: '',
            adpause: '', // http://www.ckplayer.com/yytf/swf/pause001.swf,http://www.ckplayer.com/yytf/swf/pause002.swf
            adpausetime: '5,5',
            adpauselink: '',
            adinsert: '', // http://www.ckplayer.com/yytf/swf/insert001.swf,http://www.ckplayer.com/yytf/swf/insert002.swf
            adinserttime: '10,10',
            adinsertlink: '',
            inserttime: '10,80',
            adend: '', // http://www.ckplayer.com/yytf/swf/end001.swf,http://www.ckplayer.com/yytf/swf/end002.swf
            adendtime: '15,15',
            adendlink: '',
            //广告部分结束
            promptSpot: [ //提示点
                {
                    words: '提示点文字01',
                    time: 30
                },
                {
                    words: '提示点文字02',
                    time: 150
                }
            ],
            //mobileCkControls:true,//是否在移动端（包括ios）环境中显示控制栏
            //live:true,//是否是直播视频，true=直播，false=点播
            video: [
                [basePath + videoLists.fileUrl, 'video/mp4', '中文高清', 0]
                // [basePath + videoLists.file, 'video/mp4', '英文超清', 0],
                // [basePath + videoLists.file, 'video/mp4', '英文高清', 10],
                // [basePath + videoLists.file, 'video/mp4', '中文标清', 0]
            ]
        };
        var player = new ckplayer(videoObject);
    }
}